From a3dde685e8bc5e8cd1ac811a9c7b6871a181b82e Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Thu, 10 Nov 2005 12:04:29 +0100 Subject: [PATCH] Enable xm console for vmx guest. When the serial port is redirect to pty, write the allocated device to xenstore, then xm console can get it. TODO:serial port by pty shall not block if there are no reading on the other end Signed-off-by: Xiaofeng Ling --- tools/examples/xmexample.vmx | 5 +++ tools/ioemu/target-i386-dm/Makefile | 4 +-- tools/ioemu/vl.c | 48 ++++++++++++++++++++++++++++- 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/tools/examples/xmexample.vmx b/tools/examples/xmexample.vmx index f9665ce67d..5b4ca9c5c8 100644 --- a/tools/examples/xmexample.vmx +++ b/tools/examples/xmexample.vmx @@ -117,6 +117,11 @@ vncviewer=1 #nographic=0 +#----------------------------------------------------------------------------- +# serial port re-direct to pty deivce, /dev/pts/n +# then xm console or minicom can connect +#serial='pty' + #---------------------------------------------------------------------------- # enable ne2000, default = 0(use pcnet) ne2000=0 diff --git a/tools/ioemu/target-i386-dm/Makefile b/tools/ioemu/target-i386-dm/Makefile index ba4926bfa7..3f1f9256c5 100644 --- a/tools/ioemu/target-i386-dm/Makefile +++ b/tools/ioemu/target-i386-dm/Makefile @@ -7,7 +7,7 @@ INSTALL_DIR := $(DESTDIR)/usr/$(LIBDIR)/xen/bin TARGET_PATH=$(SRC_PATH)/target-$(TARGET_ARCH) VPATH=$(SRC_PATH):$(TARGET_PATH):$(SRC_PATH)/hw:$(SRC_PATH)/audio DEFINES=-I. -I$(TARGET_PATH) -I$(SRC_PATH) -DEFINES+= -I$(XEN_ROOT)/tools/libxc +DEFINES+= -I$(XEN_ROOT)/tools/libxc -I$(XEN_ROOT)/tools/xenstore ifdef CONFIG_USER_ONLY VPATH+=:$(SRC_PATH)/linux-user DEFINES+=-I$(SRC_PATH)/linux-user -I$(SRC_PATH)/linux-user/$(TARGET_ARCH) @@ -188,7 +188,7 @@ endif ######################################################### DEFINES+=-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -LIBS+=-lm -L../../libxc -lxenctrl -lxenguest +LIBS+=-lm -L../../libxc -lxenctrl -lxenguest -L../../xenstore -lxenstore ifndef CONFIG_USER_ONLY LIBS+=-lz endif diff --git a/tools/ioemu/vl.c b/tools/ioemu/vl.c index 294e3bcdc7..89b89fb5c2 100644 --- a/tools/ioemu/vl.c +++ b/tools/ioemu/vl.c @@ -76,6 +76,7 @@ #endif /* CONFIG_SDL */ #include "xenctrl.h" +#include "xs.h" #include "exec-all.h" //#define DO_TB_FLUSH @@ -1171,6 +1172,48 @@ CharDriverState *qemu_chr_open_stdio(void) return chr; } +int store_console_dev(int domid, char *pts) +{ + int xc_handle; + unsigned int len = 0; + struct xs_handle *xs; + char *path; + + xs = xs_daemon_open(); + if (xs == NULL) { + fprintf(logfile, "Could not contact XenStore\n"); + return -1; + } + + xc_handle = xc_interface_open(); + if (xc_handle == -1) { + fprintf(logfile, "xc_interface_open() error\n"); + return -1; + } + + path = xs_get_domain_path(xs, domid); + if (path == NULL) { + fprintf(logfile, "xs_get_domain_path() error\n"); + return -1; + } + path = realloc(path, strlen(path) + strlen("/console/tty") + 1); + if (path == NULL) { + fprintf(logfile, "realloc error\n"); + return -1; + } + strcat(path, "/console/tty"); + if (!xs_write(xs, NULL, path, pts, strlen(pts))) { + fprintf(logfile, "xs_write for console fail"); + return -1; + } + + free(path); + xs_daemon_close(xs); + close(xc_handle); + + return 0; +} + #if defined(__linux__) CharDriverState *qemu_chr_open_pty(void) { @@ -1182,6 +1225,7 @@ CharDriverState *qemu_chr_open_pty(void) return NULL; } fprintf(stderr, "char device redirected to %s\n", slave_name); + store_console_dev(domid, slave_name); return qemu_chr_open_fd(master_fd, master_fd); } #else @@ -2701,7 +2745,9 @@ int main(int argc, char **argv) break; case QEMU_OPTION_nographic: pstrcpy(monitor_device, sizeof(monitor_device), "stdio"); - pstrcpy(serial_devices[0], sizeof(serial_devices[0]), "stdio"); + if(!strcmp(serial_devices[0], "vc")) + pstrcpy(serial_devices[0], sizeof(serial_devices[0]), + "stdio"); nographic = 1; break; #ifdef CONFIG_VNC -- 2.30.2